namespace DotNetNuke.UI.WebControls
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Web.UI;
    using System.Xml;

    public class TreeNodeCollection : DNNNodeCollection, IStateManager
    {
        private DnnTree m_objDNNTree;

        public TreeNodeCollection(string strNamespace, DnnTree objControl) : base(strNamespace)
        {
            this.m_objDNNTree = objControl;
        }

        public TreeNodeCollection(XmlNode objXmlNode, DnnTree objControl) : base(objXmlNode)
        {
            this.m_objDNNTree = objControl;
        }

        public TreeNodeCollection(string strXML, string strXSLFile, DnnTree objControl) : base(strXML, strXSLFile)
        {
            this.m_objDNNTree = objControl;
        }

        public int Add()
        {
            return this.Add("");
        }

        public int Add(TreeNode objNode)
        {
            int num2 = base.Add(objNode);
            objNode.SetDNNTree(this.m_objDNNTree);
            if (Strings.Len(objNode.ID) == 0)
            {
                objNode.ID = objNode.ParentNameSpace + "_" + StringType.FromInteger(objNode.GetHashCode());
            }
            return num2;
        }

        public int Add(string strText)
        {
            TreeNode objNode = new TreeNode(this.m_objDNNTree);
            int num2 = this.Add(objNode);
            objNode.Text = strText;
            return num2;
        }

        public int Add(string strID, string strKey, string strText, string strNavigateURL)
        {
            return this.Add(strID, strKey, strText, strNavigateURL, "", "", "", true, "", "", "", false, eClickAction.Navigate, "", -1);
        }

        public int Add(string strID, string strKey, string strText, string strNavigateURL, string strJSFunction, string strTarget, string strToolTip, bool blnEnabled, string strCSSClass, string strCSSClassSelected, string strCSSClassHover, bool blnSelected, eClickAction enumClickAction, string strCssClassOver, int intImageIndex)
        {
            int num2 = this.Add();
            TreeNode node = this[num2];
            if (Strings.Len(strID) > 0)
            {
                node.ID = strID;
            }
            else
            {
                node.ID = node.ParentNameSpace + "_" + StringType.FromInteger(this.XMLNode.ChildNodes.Count);
            }
            node.Key = strKey;
            node.Text = strText;
            node.NavigateURL = strNavigateURL;
            node.JSFunction = strJSFunction;
            node.Target = strTarget;
            node.ToolTip = strToolTip;
            node.Enabled = blnEnabled;
            node.CSSClass = strCSSClass;
            node.CSSClassSelected = strCSSClassSelected;
            node.CSSClassHover = strCSSClassHover;
            node.Selected = blnSelected;
            node.ClickAction = enumClickAction;
            node.CssClassOver = strCssClassOver;
            node.ImageIndex = intImageIndex;
            return num2;
        }

        public void Clear()
        {
            for (int i = this.XMLNode.ChildNodes.Count - 1; i >= 0; i += -1)
            {
                this.XMLNode.RemoveChild(this.XMLNode.ChildNodes[i]);
            }
        }

        public bool Contains(TreeNode value)
        {
            if (this.FindNode(value.ID) == null)
            {
                return false;
            }
            return true;
        }

        public TreeNode FindNode(string ID)
        {
            XmlNode objXmlNode = this.XMLNode.SelectSingleNode("//n[@id='" + ID + "']");
            if (objXmlNode != null)
            {
                return new TreeNode(objXmlNode, this.m_objDNNTree);
            }
            return null;
        }

        public TreeNode FindNodeByKey(string Key)
        {
            XmlNode objXmlNode = this.XMLNode.SelectSingleNode("//n[@key='" + Key + "']");
            if (objXmlNode != null)
            {
                return new TreeNode(objXmlNode, this.m_objDNNTree);
            }
            return null;
        }

        public override Collection FindSelectedNodes()
        {
            Collection collection = new Collection();
            if (this.XMLNode != null)
            {
                XmlNodeList list = this.XMLNode.SelectNodes("//n[@selected='1']");
                foreach (XmlNode node in list)
                {
                    collection.Add(new TreeNode(node, this.m_objDNNTree), null, null, null);
                }
            }
            return collection;
        }

        public IEnumerator GetEnumerator()
        {
            return new TreeNodeEnumerator(this.XMLNode, this.m_objDNNTree);
        }

        public int IndexOf(TreeNode value)
        {
            int num2=0;
            int count = this.XMLNode.ChildNodes.Count;
            for (int i = 0; i <= count; i++)
            {
                if (StringType.StrCmp(new TreeNode(this.XMLNode.ChildNodes[i], this.m_objDNNTree).ID, value.ID, false) == 0)
                {
                    return i;
                }
            }
            return num2;
        }

        public void Insert(int index, TreeNode value)
        {
            this.XMLNode.InsertAfter(this.XMLNode.ChildNodes[index], value.XmlNode);
        }

        public void LoadViewState(object state)
        {
        }

        public void Remove(TreeNode value)
        {
            this.XMLNode.RemoveChild(value.XmlNode);
        }

        public object SaveViewState()
        {
            //object obj2;
            //return obj2;
            return null;
        }

        public void TrackViewState()
        {
        }

        public bool IsTrackingViewState
        {
            get
            {
                return false;
            }
        }

        public TreeNode this[int index]
        {
            get
            {
                return new TreeNode(this.XMLNode.ChildNodes[index], this.m_objDNNTree);
            }
            set
            {
                throw new Exception("Cannot Assign Node Directly");
            }
        }

        //public bool System.Web.UI.IStateManager.IsTrackingViewState
        //{
        //    get
        //    {
        //        return false;
        //    }
        //}
    }
}

